﻿using MangoMes.Commont.DapperHelps;
using MangoMes.Commont.Domain;
using MangoMes.Commont.DTOs;
using MangoMes.Commont.Infrastructures.Interfaces;
using MediatR;

namespace MangoMes.Write.API.Applications.CraftRoutes
{
    public class CraftRouteUpdateHandler : IRequestHandler<CraftRouteUpdateCommand, ResultsDTO>
    {
        private readonly IBateRepository<CraftRoute> craftrouter;
        public CraftRouteUpdateHandler(IBateRepository<CraftRoute> craftrouter)
        {
            this.craftrouter = craftrouter;
        }
        /// <summary>
        /// 编辑工艺路线
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<ResultsDTO> Handle(CraftRouteUpdateCommand request, CancellationToken cancellationToken)
        {
            var list = new ResultsDTO() { Code = 0 };
            DapperHelper  helper=new DapperHelper();
            var gg=new CraftRoute();
            var str1 = "UPDATE craftroute SET RouteNo='" + request.RouteNo  + "',RouteName='" + request.RouteName + "',RouteExplain='" + request.RouteExplain + "',IsNo='" + request.IsNo + "',Comment='" + request.Comment + "' WHERE RouteId='" + request.RouteId + "'";
            var getnum = craftrouter.Add(str1, gg, helper.MangoMesWrite);
            if (getnum !=null)
            {
                list.Code = 1;
            }
            return list;
        }
    }
}
